package com.hawthorn.admin.repository.provider;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.builder.annotation.ProviderMethodResolver;

import java.util.Map;

/**
 * <p>todo job provider sql</p>
 * @author: andy.ten@tom.com | xukaixing@hotmail.com
 * @created: 2022/8/6 09:19
 * @version v1.0.1
 * @copyright: Copyright (c)  andyten
 */
@Slf4j
public class SysJobSqlProvider implements ProviderMethodResolver
{
  public static String findJobByName(String jobName)
  {
    StringBuffer sql = new StringBuffer();
    sql.append(" select\n ");
    sql.append(" 	count( id ) \n ");
    sql.append(" from\n ");
    sql.append(" 	sys_job \n ");
    sql.append(" where\n ");
    sql.append(" 	job_name = " + "'" + jobName + "'");
    return sql.toString();
  }

  public static String findJobs(Page<Map<String, Object>> page, String conditions)
  {
    StringBuffer sql = new StringBuffer();
    sql.append(" select\n ");
    sql.append(" 	id,\n ");
    sql.append(" 	model,\n ");
    sql.append(" 	bean_name beanName,\n ");
    sql.append(" 	cron_expression cronExpression,\n ");
    sql.append(" 	job_name jobName,\n ");
    sql.append(" 	method_name methodName,\n ");
    sql.append(" 	params,\n ");
    sql.append(" 	sub_task subTask,\n ");
    sql.append(" 	is_pause isPause,\n ");
    sql.append(" 	status,\n ");
    sql.append(" 	remark,\n ");
    sql.append(" 	create_time createTime \n ");
    sql.append(" from\n ");
    sql.append(" 	sys_job \n ");
    sql.append(" where");
    sql.append(conditions);
    return sql.toString();
  }

  public static String findJobLogsById(Page<Map<String, Object>> page, String conditions)
  {
    StringBuffer sql = new StringBuffer();
    sql.append(" select\n ");
    sql.append(" 	job_name jobName,\n ");
    sql.append(" 	is_success isSuccess,\n ");
    sql.append(" 	time,\n ");
    sql.append(" 	exception_detail exceptionDetail,\n ");
    sql.append(" 	create_time createTime \n ");
    sql.append(" from\n ");
    sql.append(" 	sys_job_log \n ");
    sql.append(" where");
    sql.append(conditions);
    return sql.toString();
  }
}
